#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main()
{
    //close(1);
    printf("stdin->fd: %d\n", stdin->_fileno);
    printf("stdout->fd: %d\n", stdout->_fileno);
    printf("stderr->fd: %d\n", stderr->_fileno);

    //fprintf(stderr, "printf ret: %d\n", n);

    //char buffer[1024];
    //ssize_t s = read(0, buffer, sizeof(buffer));
    //if(s < 0) return 1;
    //buffer[s] = '\0';
    //printf("echo: %s\n", buffer);

    //const char* msg = "hello Linux\n";
    //write(1, msg, strlen(msg));
    //write(2, msg, strlen(msg));


    //umask(0);
    //// file descriptor: 文件描述符，fd，int
    //// int fd = open("log.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    //int fd1 = open("log1.txt", O_WRONLY | O_CREAT | O_APPEND, 0666);
    //int fd2 = open("log2.txt", O_WRONLY | O_CREAT | O_APPEND, 0666);
    //int fd3 = open("log3.txt", O_WRONLY | O_CREAT | O_APPEND, 0666);
    //int fd4 = open("log4.txt", O_WRONLY | O_CREAT | O_APPEND, 0666);
    //if(fd1 < 0)
    //{
    //    printf("open file error\n");
    //    return 1;
    //}
    //printf("fd1: %d\n", fd1);
    //printf("fd2: %d\n", fd2);
    //printf("fd3: %d\n", fd3);
    //printf("fd4: %d\n", fd4);
    //// const char* message = "bbb";
    //// write(fd, message, strlen(message));

    //// close(fd);
    //return 0;
}

//#define ONE (1<<0) // 1
//#define TWO (1<<1) // 2
//#define FOU (1<<2) // 4
//#define EIG (1<<3) // 8
//
//void show(int flags)
//{
//    if(flags & ONE) printf("function1\n");
//    if(flags & TWO) printf("function2\n");
//    if(flags & FOU) printf("function3\n");
//    if(flags & EIG) printf("function4\n");
//
//    return;
//}
//
//int main()
//{
//    printf("--------------------------------------\n");
//    show(ONE);
//    printf("--------------------------------------\n");
//    show(ONE | TWO);
//    printf("--------------------------------------\n");
//    show(ONE | TWO | FOU );
//    printf("--------------------------------------\n");
//    show(ONE | TWO | FOU | EIG);
//    printf("--------------------------------------\n");
//    return 0;
//}

//int main()
//{
//    //chdir("/home/xny");
//    printf("pid: %d\n", getpid());
//    // 打开文件的路径和文件名，默认在当前路径下新建一个文件？
//    FILE* fp = fopen("log.txt", "w");
//    if(fp == NULL)
//    {
//        perror("fopen");
//        return 1;
//    }
//    
//    const char* message = "abcd";
//    // fwrite(message, strlen(message) + 1, 1, fp);
//    //fprintf(stdout, "%s: %d\n", message, 1234);
//    fprintf(stderr, "%s: %d\n", message, 1234);
//    fclose(fp);
//
//    return 0;
//}
